<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		echo "Working..";

		$this->db->select('*');
		$this->db->from('workflow');
		$this->db->join('workflowservicemapping', 'workflowservicemapping.workflow_id = workflow.WorkflowID');
		$this->db->join('service', 'workflowservicemapping.service_id = service.ServiceID');
		$query=$this->db->get();

		$workFlowArray=array();

		foreach ($query->result() as $row)
		{
			print_r($row);
			echo "<br/><hr/><br/>";
		}


	}
	
	public function workflow(){
		
		$orgid=$this->session->userdata['OrgID'];

		$this->db->select('WorkflowID,name');
		$this->db->from('workflow');
		$this->db->where('OrgID',0);
		$this->db->or_where('OrgID',$orgid);
		
		$query=$this->db->get();
		$workFlowArray=array();
		
		foreach($query->result() as $row){
			$workFlow=array(
				'workflow_id' => $row->WorkflowID,
				'workflow_name' => $row->name
			
			);
			$workFlowArray[]=$workFlow;
		}
		
		echo json_encode($workFlowArray);
		
	}

	public function test(){
		
		$wfid=$this->input->post("wfid",TRUE);

		$this->db->select('*');
		$this->db->from('workflow');
		$this->db->join('workflowservicemapping', 'workflowservicemapping.workflow_id = workflow.WorkflowID');
		$this->db->join('service', 'workflowservicemapping.service_id = service.ServiceID');
		$this->db->where('workflowservicemapping.workflow_id', $wfid);
		$this->db->order_by('screen_position asc, screen_order asc');
		$query=$this->db->get();



		if($query->num_rows()  > 0){
			$workFlowArray=array();
			
			//Get first row and populate workflow data
			$row = $query->row();
			$workFlowArray['workflow_service_id'] = $row->workflow_id;
			$workFlowArray['workflow_name'] = $row->name;
			
			$servicesArray=array();
			foreach ($query->result() as $row)
			{
				$service=array();
				$service['ws_id']=$row->ws_id;
				$service['service_id']=$row->service_id;
				$service['descr']=$row->descr;
				$service['screen_position']=$row->screen_position;
				$service['screen_order']=$row->screen_order;
			
				$servicesArray[] = $service;
			}
			
			$workFlowArray['service_array']=$servicesArray;
			
			
			echo json_encode($workFlowArray);
			
		}else{
			echo json_encode(array('error'=>'1'));
		}

	}

	public function testPost(){
		$objname=$this->input->post("arrayString",TRUE);
		$workFlowArray=json_decode($objname);

		$workflow_service_id=$workFlowArray->workflow_service_id;

		$serviceArray=$workFlowArray->service_array;
		$i=1;
		$text="asfasf";
			
		echo count($serviceArray);
		
		for($i=1;$i<count($serviceArray);$i++){
			$service=$serviceArray[$i];
			if(!is_null($service)){
				$data=array(
				'screen_position'=> $service->screen_position,
				'screen_order'=> $service->screen_order
				);
				$this->db->where('ws_id', $service->ws_id);
				$this->db->where('workflow_id',$workflow_service_id);
				$this->db->update('workflowservicemapping', $data);
			}
			
		
			
		//	echo $workflow_service_id." :: ".$workflow_service_id." :: ".$service->screen_position." </br>";

		}
		print_r("SUCCESS");

	}

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

/*
 //$this->load->view('welcome_message');
// 		echo "--------------------------------------";

// 		$client=new SoapClient("http://localhost:8080/MyFirstWebService/services/FirstWebService?wsdl");
// 		$result=$client->__call("sayHello", array());

// 		print_r($result);
// 		echo "<br>";
// 		echo "--------------------------------------";

$this->load->view('soapclienttest');
*
*
// 		$client=new SoapClient("http://localhost:8080/SunShopWebService/services/SunShopWebService?wsdl");
// 		$result=$client->readAllObjects(array('orgId'=>1));
// 		print_r($result->return);
$abc='[["One"],["Two","Three"],["Four","Five","Six"],["Seven"],["Eight"],["Nine","Ten"]]';
$bcd=json_decode($abc);
print_r($bcd);
echo count($bcd[2]);
// 		$requestArray=array(
// 						'orgId'=>1,
// 						'objName'=>"Laptop",
// 						'fieldName'=>'tax',
// 						'dataType'=>'DOUBLE',
// 						'reference'=>null,
// 						'fieldNum'=>2
	
// 		);
// 		$client=new SoapClient("http://localhost:8080/SunShopWebService/services/SunShopWebService?wsdl");
// 		$result=$client->createField($requestArray);
// 		echo $result->return;

*/
